package cn.edu.sdyu.ie.crs.api;

import cn.edu.sdyu.ie.crs.domain.Device;
import cn.edu.sdyu.ie.crs.iot.HomeAssistantService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DeviceCController {

    @Autowired
    private HomeAssistantService homeAssistantService;

    @RequestMapping("a")
    @ResponseBody
    public String a() {
        Device device = new Device();
        device.setEntityId("light.192_168_2_131");
        device.setDeviceType(1);
        homeAssistantService.turnOn(device);

        return "a";
    }

    @RequestMapping("b")
    @ResponseBody
    public String b() {
        Device device = new Device();
        device.setEntityId("light.192_168_2_131");
        device.setDeviceType(1);
        homeAssistantService.turnOff(device);

        return "a";
    }

    @RequestMapping("c")
    @ResponseBody
    public String c() throws JsonProcessingException {
        Device device = new Device();
        device.setEntityId("light.192_168_2_131");
        device.setDeviceType(1);
        homeAssistantService.getState(device);

        return "a";
    }

}
